package org.taohuawu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.taohuawu.pojo.Item;
import org.taohuawu.pojo.Order;
import org.taohuawu.pojo.User;
import org.taohuawu.service.ItemFeignService;
import org.taohuawu.service.ItemService;
import org.taohuawu.service.OrderFeignService;
import org.taohuawu.service.UserFeignService;
import org.taohuawu.web.util.JsonResult;

import java.util.List;

@RestController
public class FeignController {
    @Autowired
    private ItemFeignService itemFeignService;

    @Autowired
    private UserFeignService userFeignService;

    @Autowired
    private OrderFeignService orderFeignService;

    // http://localhost:3001/item-service/35
    @GetMapping("/item-service/{orderId}")
    public JsonResult<List<Item>> getItems(@PathVariable String orderId) {
        return itemFeignService.getItems(orderId);
    }

    // http://localhost:3001/item-service/decreaseNumber
    // [{"id":1},{"id":2},{"id":3}]
    @PostMapping("/item-service/decreaseNumber")
    public JsonResult decreaseNumber(@RequestBody List<Item> items) {
        return itemFeignService.decreaseNumber(items);
    }

    // http://localhost:3001/user-service/8
    @GetMapping("/user-service/{userId}")
    public JsonResult<User> getUser(@PathVariable Integer userId){
        return userFeignService.getUser(userId);
    }

    // http://localhost:3001/user-service/9/score&score=98
    @GetMapping("/user-service/{userId}/score")
    public JsonResult addScore(@PathVariable Integer userId, Integer score){
        return userFeignService.addScore(userId, score);
    }

    // http://localhost:3001/order-service/202107225645811
    @GetMapping("/order-service/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId){
        return orderFeignService.getOrder(orderId);
    }

    // http://localhost:3001/order-service/add
    @GetMapping("/order-service/add")
    public JsonResult addOrder(){
        return orderFeignService.addOrder();
    }
}
